//定时 5 15 * * * 

var url = "http://jdcloudwifi.com/jdcapi"
var password = "linshimima"


var request = require('request');
var post_data = {
                    "jsonrpc": "2.0",
                    "id": 1,
                    "method": "call",
                    "params": [
                        "00000000000000000000000000000000",
                        "session",
                        "login",
                        {
                            "username": "root",
                            "password": password,
                            "timeout": 600
                        }
                    ]
                };
 

function postAction(url,post_data,methdo_type,sessid) {
    request.post({
        url: url,
        json: true,
        headers: {
            'Content-length': post_data.length,
            "Content-Type": "application/x-www-form-urlencoded",
			'Cookie': 'work_mode_flag=0; HostAddrIP=jdcloudwifi.com; wan_proto=wds; model=jdc-ss01; platform=Atheros; sessionid='+sessid
        },
        body: JSON.stringify(post_data)
    },
        (error, response, body) => {

            if (!error && response.statusCode == 200) {
                console.log("-----response------->>>", body);
				//console.log("-----response------->>>", methdo_type,body.result[1].ubus_rpc_session);


                if (methdo_type == 'login'){
					
                    methdo_type = "xiansu"
                    post_data = {
                                    "jsonrpc": "2.0",
                                    "id": 20,
                                    "method": "call",
                                    "params": [body.result[1].ubus_rpc_session, "jdcapi.static", "set_nat_type", {
                                            "type": "nat1"
                                        }
                                    ]
                                };
                    console.log("---------post_data--->>>", post_data);
                    console.log("---seconed---"+url,post_data,methdo_type,body.result[1].ubus_rpc_session)
                    postAction(url,post_data,methdo_type,body.result[1].ubus_rpc_session);





					
                    post_data = {"jsonrpc": "2.0",
                                    "id": 20,
                                    "method": "call",
                                    "params": [body.result[1].ubus_rpc_session, "jdcapi.static", "set_upnp", {
                                            "enabled": 0
                                        }
                                    ]
                                };
                    console.log("---------post_data--->>>", post_data);
                    console.log("---seconed---"+url,post_data,methdo_type,body.result[1].ubus_rpc_session)
                    postAction(url,post_data,methdo_type,body.result[1].ubus_rpc_session);
					


                }else{
                    //调速




                }



            }{
                
            }
        }
    );
}
methdo_type = "login"
postAction(url,post_data,methdo_type,null);